//
//  MoreViewController.m
//  QuickReadComic
//
//  Created by 苗钧豪 on 16/9/16.
//  Copyright © 2016年 苗钧豪. All rights reserved.
//

#import "MoreViewController.h"
#import "MoreTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "MainViewController.h"
#import "FoundViewController.h"
@interface MoreViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableview;
@property(nonatomic,strong)UIView *headerView;
@property(nonatomic,strong)UIImageView *headerImageView;
@property(nonatomic,strong)UIImageView *nicNameImageView;
@end

@implementation MoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:(UIBarButtonSystemItemReply) target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem = item;
    self.tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, -64, self.view.bounds.size.width, self.view.bounds.size.height) style:(UITableViewStylePlain)];
    self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 300)];
    self.headerView.backgroundColor = [UIColor blueColor];
    self.headerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 300)];
    self.headerImageView.backgroundColor = [UIColor redColor];
    [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:self.imageUrlString]];
    [self.headerView addSubview:self.headerImageView];
    
    self.nicNameImageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, self.view.bounds.size.width / 2 - 50, 100, 100)];
    CALayer *layer = self.nicNameImageView.layer;
    [layer setMasksToBounds:YES];
    [layer setCornerRadius:50];
//    [self.nicNameImageView sd_setImageWithURL:[NSURL URLWithString:self.model.user.avatar_url]];
    
    self.tableview.tableHeaderView = self.headerView;
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.estimatedRowHeight = 1000;
    self.tableview.rowHeight = UITableViewAutomaticDimension;
    [self.tableview registerNib:[UINib nibWithNibName:@"MoreTableViewCell" bundle:nil] forCellReuseIdentifier:@"more"];
    [self.view addSubview:self.tableview];
}
- (void)back {
    MainViewController *vc = [[MainViewController alloc]init];
    [UIApplication sharedApplication].keyWindow.rootViewController = vc;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat offset_Y = scrollView.contentOffset.y;
    if (offset_Y < 0) {
        CGFloat add_height = -(offset_Y + 0);
        CGFloat scale = (add_height + 200) / 200.0f;
        self.headerImageView.frame = CGRectMake(-(self.headerView.bounds.size.width * scale - self.headerView.bounds.size.width) / 2.0f, - add_height, self.headerView.bounds.size.width * scale, 300 + add_height);
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MoreTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"more"];
    cell.namelabel.text = self.descriptionString;
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
